﻿using IBLL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MODEL;

namespace API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class LoginController : ControllerBase
    {
        public LoginController(IManagerBLL bll,ILogger<LoginController> logger)
        {
            Bll = bll;
            Logger = logger;
        }

        public IManagerBLL Bll { get; }
        public ILogger<LoginController> Logger { get; }
        /// <summary>
        /// 账号信息表集合
        /// </summary>
        /// <returns>返回集合</returns>
        [HttpGet]
        public List<ManagerInfo> GetManagers()
        {
            try
            {
                Logger.LogInformation("获取账号信息");
                return Bll.GetManagers();
            }
            catch (Exception)
            {
                Logger.LogError("出现异常，抛出");
                throw;
            }
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="num">登录账号</param>
        /// <param name="pwd">密码</param>
        /// <returns>返回账号信息表对象</returns>
        [HttpGet]
        public async Task<ManagerInfo> LoginInfo(string num, string pwd)
        {
            try
            {
                Logger.LogInformation("执行登录功能");
                return await Bll.LoginInfo(num, pwd);
            }
            catch (Exception)
            {
                Logger.LogError("出现异常，抛出");
                throw;
            }
        }
    }
}
